package com.vidmt.api.modules.sys.web;

import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.vidmt.api.common.pojo.ApiResultServer;
import com.vidmt.api.common.utils.AES128Coder;
import com.vidmt.api.common.utils.StrUtil;
import com.vidmt.api.common.web.ApiController;
import com.vidmt.api.modules.sys.auth.AuthFactory;

/**
 * 系统属性Controller
 * 
 * @author xingqisheng
 * @version 2015-08-14
 */
@Controller
@RequestMapping(value = "${adminPath}/web/sys")
public class WebUtilController extends ApiController {
	private DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();

	@RequestMapping(value = "/util.html")
	public String apitest(Model model) {
		return "modules/sys/util";
	}

	@ResponseBody
	@RequestMapping(value = "/util/decodepwd.*")
	public ApiResultServer decodepwd(String cyphered) {
		return new ApiResultServer(AuthFactory.decodePwd(cyphered));
	}
	
	@ResponseBody
	@RequestMapping(value = "/util/encodeacctxt.*")
	public ApiResultServer encodeacctxt(String acctxt,String os,String ver) {
		String key=os + ver.toString();
		AES128Coder des = new AES128Coder(StrUtil.bytesutf8(key));
		return new ApiResultServer(des.encrypt(StrUtil.bytesutf8(acctxt)));
	}
}